import {Component} from 'react';
import WithRoute from '../router/withRoute';
class Home extends Component{
    state = {
        list:[
            {
                name:"辣条",
                price:10
            },{
                name:"牛奶",
                price:5
            },{
                name:"可乐",
                price:3
            }
        ]
    }
    render(){
        return(
            <div>
                <h1>首页</h1>
                <ol>
                    {
                        this.state.list.map((item,index)=>{
                            return <li key={index} onClick={()=>this.goInfo(item)}>{item.name}----{item.price}</li>
                        })
                    }
                </ol>
            </div>
        )
    }
    goInfo(item){
            let {name,price} = item;
            // this.props.router.navigate(`/info/${name}/${price}`)
            this.props.router.navigate(`/info`,{
                // 编程式跳转state传参
                state:{
                    name,
                    price
                }
            })
    }
}
export default WithRoute(Home);